package juc;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import redislock.RedisLock;

public class FenbushiTest
{
    //模拟有100件香蕉
    static int i = 5;

    //key的前缀
    public static final String KEY = "redisLock";
    //模拟多线程实现秒杀
    public static void main(String[] args) throws InterruptedException
    {

        Logger.getLogger("org.apache.spark").setLevel(Level.ERROR);
        Logger.getLogger("org.eclipse.jetty.server").setLevel(Level.OFF);
        //模拟两千只猴进行抢购
        for (int j = 0; j < 2000; j++)
        {
            new Thread(()->{
                RedisLock.lock(KEY);
                    if (i == 0)
                    {
                        System.out.println("抢购结束，没有商品鸟~~~~"+Thread.currentThread().getName());
                    }else
                    {
                        System.out.println(Thread.currentThread().getName()+"抢到了第"+(6-i)+"件商品");
                        i--;
                    }
                RedisLock.unlock(KEY);
            },String.valueOf(j)).start();

        }

    }
}
